// 验证码发送记录
import { DataTypes, UUIDV4 } from 'sequelize';
import { MySqlModel, getSequelize } from '../db';

class SMSCaptcha extends MySqlModel {

}

SMSCaptcha.init({
  id: {
    type: DataTypes.UUID, unique: 'id', allowNull: false, defaultValue: UUIDV4, validate: { isUUID: 4 }, primaryKey: true, comment: '主键'
  },
  hotel_id: {
    type: DataTypes.UUID, allowNull: false, validate: { isUUID: 4 }, comment: '主体'
  },
  openid: {
    type: DataTypes.STRING(50), allowNull: false, comment: 'openid'
  },
  mobile: {
    type: DataTypes.STRING(50), allowNull: false, comment: '手机号'
  },
  captcha: {
    type: DataTypes.STRING(6), allowNull: false, comment: '验证码'
  },
  expired_at: { // 失效的验证码无法使用
    type: DataTypes.BIGINT, allowNull: false, comment: '有效期'
  },
  business_date: { // 用于控制验证码每日次数
    type: DataTypes.STRING(10), allowNull: false, comment: '验证码日期'
  },
  ip_address: { // 终端IP地址
    type: DataTypes.STRING(20), allowNull: true, defaultValue: null, comment: 'IP地址'
  },
  created_at: {
    type: DataTypes.DATE, allowNull: false, editable: false, comment: '创建时间'
  },
  updated_at: {
    type: DataTypes.DATE, allowNull: false, editable: false, comment: '更新时间'
  }
}, {
  sequelize: getSequelize(),
  tableName: 'sms_captcha',
  comment: '验证码记录'
});

export default SMSCaptcha;
